package com.wowudi.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wowudi.dto.Result;
import com.wowudi.entity.Department;
import com.wowudi.entity.DepartmentClass;
import com.wowudi.mapper.DepartmentClassMapper;
import com.wowudi.service.DepartmentClassService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@Api(tags = "部门管理")
@RequestMapping("api/dept/dept")
public class DepartmentClassController {

    @Autowired
    private DepartmentClassService departmentClassService;

    @Autowired
    private DepartmentClassMapper departmentClassMapper;

    @ApiOperation(value = "查询所有科室")
    @GetMapping("getDepartmentClass")
    public Result getDepartment(){
        List<DepartmentClass> departmentClassList = departmentClassService.findDepartmentClassAll();
        Result result = new Result();
        result.setData(departmentClassList);
        return result;
    }
    @RequestMapping("outdep")
    public Page<DepartmentClass> selectoutdep(int pages, int sizes) {
        Page<DepartmentClass> productIPage=new Page<>(pages, sizes);
        productIPage=departmentClassService.page(productIPage);

//        Page<Map<String, Object>> productIPage=departmentClassService.selectListPage(1, 2);
        return productIPage;
    }

    @RequestMapping("dpcdep")
    public IPage<DepartmentClass> selectdpcdep(int pages, int sizes, String dpcname) {
        QueryWrapper<DepartmentClass> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("dpc_name", dpcname);
        Page<DepartmentClass> productIPage=new Page<>(pages, sizes);
        IPage<DepartmentClass> pageList = departmentClassMapper.selectPage(productIPage, queryWrapper);
        return pageList;
    }

    @RequestMapping("add")
    public String adddpc(String dpc_name,int cdp_id,String dpc_description,String dpc_iscure) {
        DepartmentClass departmentClass = new DepartmentClass();
        departmentClass.setDpcName(dpc_name);
        departmentClass.setDpId(cdp_id);
        departmentClass.setDpcDescription(dpc_description);
        departmentClass.setDpcIscure(dpc_iscure);
        departmentClassMapper.insert(departmentClass);
        return "";
    }

}
